from homework2.Page import Page
import pytest,time
from selenium import webdriver
from selenium.webdriver.common.by import By

class TestCase:
    @pytest.fixture(scope='function')
    def page(self):
        driver = webdriver.Edge()
        driver.maximize_window()
        try:
            driver.get('https://www.baidu.com/')
            yield driver
        except Exception as e:
            print(e)
            yield None
        finally:
            if driver:
                driver.quit()

    def test_01(self,page):
        po = Page(page)
        po.search()
        po.searchbtn()
        page.implicitly_wait(5)
        title = page.find_element(By.XPATH,'/html/body/div[3]/div[3]/div[1]/div[3]/div[1]/div/div/div[3]/div/div/div/div[1]/h3/div/a')
        po.two()
        print(title)

    def test_02(self,page):
        po = Page(page)
        po.new()
        new = page.find_element(By.XPATH,'/html/body/div[3]/div[2]/div[1]/div/div[2]/ul/li/a')
        assert '热点要闻' == new
        time.sleep(5)

    def test_03(self,page):
        po = Page(page)
        po.map()
        time.sleep(5)

    def test_04(self,page):
        po = Page(page)
        po.tie()
        time.sleep(5)

    def test_05(self,page):
        po = Page(page)
        po.video()
        time.sleep(5)